/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogoCancelarReencauche.java
 *
 * Created on 14-may-2013, 0:42:43
 */
package com.camachosanchez.gui;

import com.camachosanchez.bean.Categorias;
import com.camachosanchez.bean.ControlReencauche;
import com.camachosanchez.bean.DetalleControlReencauche;
import com.camachosanchez.bean.Neumaticos;
import com.camachosanchez.controler.jdbc.ControlReencaucheJdbcControler;
import com.camachosanchez.controler.jpa.CategoriasJpaController;
import com.camachosanchez.controler.jpa.ControlReencaucheJpaController;
import com.camachosanchez.gui.combo.WideComboBoxEditor;
import com.camachosanchez.gui.combo.WideComboBoxRenderer;
import com.camachosanchez.gui.table.ModeloTablaReencauche;
import com.camachosanchez.gui.table.RenderizadorTabla;
import com.camachosanchez.gui.table.RenderizadorTablaCancelarEnvioMarcado;
import com.camachosanchez.gui.table.TableSorter;
import com.camachosanchez.util.Constantes;
import com.camachosanchez.util.GUIUtil;
import com.camachosanchez.util.JPAUtil;
import java.awt.CardLayout;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import net.coderazzi.filters.gui.TableFilterHeader;

/**
 *
 * @author Rolando
 */
public class DialogoCancelarReencauche extends javax.swing.JDialog {

    private ModeloTablaReencauche modelo;
    private TableFilterHeader filterHeader;
    private TableSorter tableSorter;
    private DefaultTableModel dm;
    private CardLayout card;
    private ControlReencauche controlReencauche;
    private EntityManagerFactory emf = null;
    HashMap<String, Short> hm = new HashMap<String, Short>();
    List<Categorias> listaCategorias;
    List<String> descripcionCategorias;

    /** Creates new form DialogoCancelarReencauche */
    public DialogoCancelarReencauche(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.emf = JPAUtil.getEntityManagerFactory();
        GUIUtil.addEscapeKey(this);
        card = (CardLayout) getContentPane().getLayout();
        modelo = new ModeloTablaReencauche();
        tableSorter = new TableSorter(modelo, tblEnvios.getTableHeader());
        tblEnvios.setModel(tableSorter);
        filterHeader = new TableFilterHeader();
        filterHeader.setTable(tblEnvios);
        RenderizadorTabla render = new RenderizadorTabla();
        tblEnvios.setDefaultRenderer(String.class, render);
        llenarTabla();
        CategoriasJpaController emc = new CategoriasJpaController(null);
        listaCategorias = emc.findCategoriasEntities();
        descripcionCategorias = new ArrayList<String>();
        if (listaCategorias != null) {
            for (Categorias item : listaCategorias) {
                if (item.getId().equals(Constantes.CATEGORIA_BODEGA) || item.getId().equals(Constantes.CATEGORIA_CEMENTERIO) || item.getId().equals(Constantes.CATEGORIA_STOCK)) {
                    hm.put(item.getNombre(), item.getId().shortValue());
                    descripcionCategorias.add(item.getNombre());
                }
            }
        }

        RenderizadorTablaCancelarEnvioMarcado render2 = new RenderizadorTablaCancelarEnvioMarcado(tblDetalleEnvio.getTableHeader().getDefaultRenderer());
        dm = new DefaultTableModel() {

            @Override
            public boolean isCellEditable(int row, int col) {
                if (col == 0 || col == 8) {
                    return true;
                }
                return false;
            }

            @Override
            public Class getColumnClass(int c) {
                if (c == 0) {
                    return Boolean.class;
                }
                return String.class;
            }
        };
        Object[] columns = new Object[]{"CANCELAR", "CÓDIGO", "BANDA ACTUAL", "NUEVA BANDA", "PISO ACTUAL", "NUEVO PISO", "PRECIO", "GARANTÍA", "DESTINO"};
        dm.setColumnIdentifiers(columns);
        tblDetalleEnvio.setModel(dm);
        tblDetalleEnvio.setDefaultRenderer(String.class, render2);
        tblDetalleEnvio.getColumnModel().getColumn(0).setCellRenderer(render2);
        tblDetalleEnvio.setRowHeight(22);
        tblEnvios.setRowHeight(22);
        setSize(800, 400);
        setLocationRelativeTo(null);
    }

    private void llenarTabla() {
        modelo.limpiar();
        ControlReencaucheJdbcControler daoJdbc = new ControlReencaucheJdbcControler();
        List<ControlReencauche> registros = daoJdbc.findEnvios();
        for (ControlReencauche control : registros) {
            modelo.agregarRegistro(control);
        }
        tblDetalleEnvio.getTableHeader().setReorderingAllowed(false);
        GUIUtil.SetAnchoColumnas(tblEnvios);
        ocultarColumna();
    }

    private void ocultarColumna() {
        int anchoColumna = 0;
        TableColumnModel modeloColumna = tblEnvios.getColumnModel();
        TableColumn columnaTabla;
        for (int i = 0; i < tblEnvios.getColumnCount(); i++) {
            columnaTabla = modeloColumna.getColumn(i);
            switch (i) {
                case 7:
                    anchoColumna = 0;
                    columnaTabla.setMinWidth(anchoColumna);
                    columnaTabla.setMaxWidth(anchoColumna);
                    columnaTabla.setPreferredWidth(anchoColumna);
                    break;
            }
        }
    }

    private void limpiarTabla() {
        while (dm.getRowCount() != 0) {
            dm.removeRow(0);
        }
    }

    private void llenarPanelEnvio(int row) {
        this.limpiarTabla();
        ControlReencaucheJpaController dao = new ControlReencaucheJpaController(null);
        controlReencauche = dao.findControlReencauche(row);
        txtDireccion.setText(controlReencauche.getDireccion());
        txtDistribuidor.setText(controlReencauche.getIdDistribuidorNeumaticos().getNombre());
        Format formatter;
        formatter = new SimpleDateFormat("dd/MM/yyyy");
        String fecha = formatter.format(controlReencauche.getFechaEnvio());
        txtFecha.setText(fecha);
        txtTelefono.setText(controlReencauche.getTelefono());
        txtNroGuia.setText("Nº " + controlReencauche.getNumGuiaRemision());
        List<DetalleControlReencauche> detalle = controlReencauche.getDetalleControlReencaucheList();
        int filaDm = 0;
        for (DetalleControlReencauche item : detalle) {
            if (item.getFechaRecepcion() == null && item.getEstado()) {// para los neumáticos aún no recepcionados
                Object[] fila = new Object[9];
                fila[0] = Boolean.FALSE;
                fila[1] = item.getIdNeumatico().getCodigo();
                fila[2] = (item.getIdNeumatico().getIdBanda() == null) ? "" : item.getIdNeumatico().getIdBanda().getNombre();
                fila[3] = item.getIdNuevoTipoBanda().getNombre();
                fila[4] = (item.getIdNeumatico().getTipoPiso() == null) ? "" : item.getIdNeumatico().getTipoPiso().getNombre();
                fila[5] = item.getIdNuevoTipoPiso().getNombre();
                fila[6] = GUIUtil.formatearNumero(item.getPrecio());
                fila[7] = (item.getPorGarantia()) ? "√" : "";
                if (listaCategorias != null && !listaCategorias.isEmpty()) {
                    fila[8] = listaCategorias.get(0).getNombre();
                } else {
                    fila[8] = "";
                }
                dm.addRow(fila);
                filaDm++;
            }
        }
        TableColumn col = tblDetalleEnvio.getColumnModel().getColumn(8);
        col.setCellEditor(new WideComboBoxEditor(descripcionCategorias));
        col.setCellRenderer(new WideComboBoxRenderer(descripcionCategorias));
        GUIUtil.SetAnchoColumnas(tblDetalleEnvio);
    }

    private boolean estaRecepcionadoTotal(List<DetalleControlReencauche> detalle) {
        for (DetalleControlReencauche item : detalle) {
            if (item.getFechaRecepcion() == null && item.getEstado()) {
                return false;
            }
        }
        return true;
    }

    private boolean estaTodoDetalleCancelado(List<DetalleControlReencauche> detalle) {
        for (DetalleControlReencauche item : detalle) {
            if (item.getEstado()) {
                return false;
            }
        }
        return true;
    }

    private void cancelarEnvio() {
        EntityManager em = null;
        try {
            em = emf.createEntityManager();
            EntityTransaction tx = em.getTransaction();
            tx.begin();
            int fila = 0;
            controlReencauche = (ControlReencauche) em.getReference(ControlReencauche.class, controlReencauche.getId());
            List<DetalleControlReencauche> detalle = controlReencauche.getDetalleControlReencaucheList();
            for (DetalleControlReencauche item : detalle) {
                if (item.getFechaRecepcion() == null && item.getEstado()) {
                    Neumaticos neumatico = (Neumaticos) em.getReference(Neumaticos.class, item.getIdNeumatico().getId());
                    if (Boolean.parseBoolean(dm.getValueAt(fila, 0).toString())) {//si es cancelado
                        Categorias categoriaNueva = new Categorias(hm.get(dm.getValueAt(fila, 8).toString()).intValue());
                        neumatico.setIdCategoria(categoriaNueva);
                        item.setEstado(false);
                    }
                    item.setIdNeumatico(neumatico);
                    fila++;
                }
            }
            if (estaRecepcionadoTotal(detalle)) {
                controlReencauche.setEstadoTransaccion(true);
                controlReencauche.setNumFactura("");
                controlReencauche.setFechaRecepcion(new Date());
                controlReencauche.setEstadoTransaccion(true);
                if (estaTodoDetalleCancelado(detalle)) {
                    controlReencauche.setEstado(false);
                }
            }
            em.persist(controlReencauche);
            tx.commit();
            JOptionPane.showMessageDialog(this, "Se ha cancelado con éxito el envío a reencauche.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
            dispose();
        } catch (Exception e) {
            em.getTransaction().rollback();
            e.printStackTrace();
            JOptionPane.showMessageDialog(Principal.getInstance(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlUno = new javax.swing.JPanel();
        pnlOpcionesUno = new javax.swing.JPanel();
        btnAnterior1 = new javax.swing.JButton();
        btnSiguiente1 = new javax.swing.JButton();
        btnAnular1 = new javax.swing.JButton();
        scrEnvios = new javax.swing.JScrollPane();
        tblEnvios = new javax.swing.JTable();
        pnlDos = new javax.swing.JPanel();
        pnlOpcionesDos = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        btnAnular2 = new javax.swing.JButton();
        pnlDatosEnvio = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        lblDireccion = new javax.swing.JLabel();
        jPanel14 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        lblNumGuia = new javax.swing.JLabel();
        lblFecha = new javax.swing.JLabel();
        jPanel11 = new javax.swing.JPanel();
        txtNroGuia = new javax.swing.JTextField();
        txtFecha = new javax.swing.JTextField();
        jPanel17 = new javax.swing.JPanel();
        jPanel18 = new javax.swing.JPanel();
        txtDistribuidor = new javax.swing.JTextField();
        jPanel19 = new javax.swing.JPanel();
        lblTelefono = new javax.swing.JLabel();
        txtTelefono = new javax.swing.JTextField();
        txtDireccion = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblDetalleEnvio = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(".:: Cancelar Envío a Reencauche ::.");
        setResizable(false);
        getContentPane().setLayout(new java.awt.CardLayout());

        pnlUno.setLayout(new java.awt.BorderLayout());

        btnAnterior1.setBackground(new java.awt.Color(255, 255, 204));
        btnAnterior1.setText("<<Anterior");
        btnAnterior1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnAnterior1.setContentAreaFilled(false);
        btnAnterior1.setEnabled(false);
        btnAnterior1.setOpaque(true);
        btnAnterior1.setPreferredSize(new java.awt.Dimension(57, 21));
        pnlOpcionesUno.add(btnAnterior1);

        btnSiguiente1.setBackground(new java.awt.Color(255, 255, 204));
        btnSiguiente1.setText("Siguiente>>");
        btnSiguiente1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnSiguiente1.setContentAreaFilled(false);
        btnSiguiente1.setOpaque(true);
        btnSiguiente1.setPreferredSize(new java.awt.Dimension(63, 21));
        btnSiguiente1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSiguiente1ActionPerformed(evt);
            }
        });
        pnlOpcionesUno.add(btnSiguiente1);

        btnAnular1.setBackground(new java.awt.Color(255, 255, 204));
        btnAnular1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/16_cancel.png"))); // NOI18N
        btnAnular1.setText("Anular envío");
        btnAnular1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnAnular1.setContentAreaFilled(false);
        btnAnular1.setEnabled(false);
        btnAnular1.setOpaque(true);
        pnlOpcionesUno.add(btnAnular1);

        pnlUno.add(pnlOpcionesUno, java.awt.BorderLayout.PAGE_END);

        tblEnvios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        scrEnvios.setViewportView(tblEnvios);

        pnlUno.add(scrEnvios, java.awt.BorderLayout.CENTER);

        getContentPane().add(pnlUno, "card2");

        pnlDos.setLayout(new java.awt.BorderLayout());

        jButton2.setBackground(new java.awt.Color(255, 255, 204));
        jButton2.setText("<<Anterior");
        jButton2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jButton2.setContentAreaFilled(false);
        jButton2.setOpaque(true);
        jButton2.setPreferredSize(new java.awt.Dimension(57, 21));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        pnlOpcionesDos.add(jButton2);

        jButton1.setBackground(new java.awt.Color(255, 255, 204));
        jButton1.setText("Siguiente>>");
        jButton1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jButton1.setContentAreaFilled(false);
        jButton1.setEnabled(false);
        jButton1.setOpaque(true);
        jButton1.setPreferredSize(new java.awt.Dimension(63, 21));
        pnlOpcionesDos.add(jButton1);

        btnAnular2.setBackground(new java.awt.Color(255, 255, 204));
        btnAnular2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/16_cancel.png"))); // NOI18N
        btnAnular2.setText("Anular envío");
        btnAnular2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnAnular2.setContentAreaFilled(false);
        btnAnular2.setOpaque(true);
        btnAnular2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnular2ActionPerformed(evt);
            }
        });
        pnlOpcionesDos.add(btnAnular2);

        pnlDos.add(pnlOpcionesDos, java.awt.BorderLayout.PAGE_END);

        pnlDatosEnvio.setLayout(new java.awt.BorderLayout());

        jPanel5.setLayout(new java.awt.BorderLayout(4, 4));

        jPanel6.setLayout(new java.awt.GridLayout(2, 1, 4, 4));

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel5.setText("Distribuidor:");
        jPanel6.add(jLabel5);

        lblDireccion.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lblDireccion.setText("Dirección:");
        jPanel6.add(lblDireccion);

        jPanel5.add(jPanel6, java.awt.BorderLayout.LINE_START);

        jPanel14.setMinimumSize(new java.awt.Dimension(200, 100));
        jPanel14.setPreferredSize(new java.awt.Dimension(200, 100));
        jPanel14.setLayout(new java.awt.BorderLayout());

        jPanel10.setPreferredSize(new java.awt.Dimension(45, 48));
        jPanel10.setLayout(new java.awt.GridLayout(2, 1, 2, 4));

        lblNumGuia.setText("Guía Nº:");
        jPanel10.add(lblNumGuia);

        lblFecha.setText("Fecha:");
        jPanel10.add(lblFecha);

        jPanel14.add(jPanel10, java.awt.BorderLayout.LINE_START);

        jPanel11.setLayout(new java.awt.GridLayout(2, 1, 2, 4));

        txtNroGuia.setEditable(false);
        txtNroGuia.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtNroGuia.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel11.add(txtNroGuia);

        txtFecha.setEditable(false);
        txtFecha.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtFecha.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel11.add(txtFecha);

        jPanel14.add(jPanel11, java.awt.BorderLayout.CENTER);

        jPanel5.add(jPanel14, java.awt.BorderLayout.LINE_END);

        jPanel17.setLayout(new java.awt.GridLayout(2, 1, 4, 4));

        jPanel18.setLayout(new java.awt.GridLayout(1, 3, 4, 4));

        txtDistribuidor.setEditable(false);
        txtDistribuidor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        txtDistribuidor.setMaximumSize(new java.awt.Dimension(180, 23));
        txtDistribuidor.setMinimumSize(new java.awt.Dimension(180, 23));
        txtDistribuidor.setPreferredSize(new java.awt.Dimension(160, 23));
        jPanel18.add(txtDistribuidor);

        jPanel19.setLayout(new java.awt.BorderLayout(4, 4));

        lblTelefono.setText("Teléfono:");
        jPanel19.add(lblTelefono, java.awt.BorderLayout.LINE_START);

        txtTelefono.setEditable(false);
        txtTelefono.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        txtTelefono.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        txtTelefono.setMaximumSize(new java.awt.Dimension(120, 23));
        txtTelefono.setMinimumSize(new java.awt.Dimension(120, 23));
        txtTelefono.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel19.add(txtTelefono, java.awt.BorderLayout.CENTER);

        jPanel18.add(jPanel19);

        jPanel17.add(jPanel18);

        txtDireccion.setEditable(false);
        txtDireccion.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        txtDireccion.setMaximumSize(new java.awt.Dimension(205, 23));
        txtDireccion.setMinimumSize(new java.awt.Dimension(205, 23));
        txtDireccion.setPreferredSize(new java.awt.Dimension(205, 23));
        jPanel17.add(txtDireccion);

        jPanel5.add(jPanel17, java.awt.BorderLayout.CENTER);

        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel13.setText("<html><font color='red'>(*)</font> Seleccione solo los neumáticos a cancelar el envío.</html>");
        jLabel13.setPreferredSize(new java.awt.Dimension(60, 14));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlDatosEnvio.add(jPanel1, java.awt.BorderLayout.PAGE_START);

        tblDetalleEnvio.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblDetalleEnvio);

        pnlDatosEnvio.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        pnlDos.add(pnlDatosEnvio, java.awt.BorderLayout.CENTER);

        getContentPane().add(pnlDos, "card3");

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
    card.show(getContentPane(), "card2");
}//GEN-LAST:event_jButton2ActionPerformed

private void btnSiguiente1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSiguiente1ActionPerformed
// TODO add your handling code here:
    int row = tblEnvios.getSelectedRow();
    if (row > -1) {
        int value = Integer.parseInt(modelo.getValueAt(row, 7).toString());
        card.show(getContentPane(), "card3");
        llenarPanelEnvio(value);
    }
}//GEN-LAST:event_btnSiguiente1ActionPerformed

private void btnAnular2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnular2ActionPerformed
// TODO add your handling code here:
    boolean finalizar = false;
    for (int fila = 0; fila < dm.getRowCount(); fila++) {
        if (Boolean.parseBoolean(dm.getValueAt(fila, 0).toString())) {
            finalizar = true;
            break;
        }
    }
    if (finalizar) {
        cancelarEnvio();
    } else {
        JOptionPane.showMessageDialog(this, "Debe seleccionar al menos un neumatico para su cancelación.", "Advertencia", JOptionPane.WARNING_MESSAGE);
    }
}//GEN-LAST:event_btnAnular2ActionPerformed
//    /**
//     * @param args the command line arguments
//     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(DialogoCancelarReencauche.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(DialogoCancelarReencauche.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(DialogoCancelarReencauche.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(DialogoCancelarReencauche.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the dialog */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                DialogoCancelarReencauche dialog = new DialogoCancelarReencauche(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//
//                    @Override
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAnterior1;
    private javax.swing.JButton btnAnular1;
    private javax.swing.JButton btnAnular2;
    private javax.swing.JButton btnSiguiente1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblDireccion;
    private javax.swing.JLabel lblFecha;
    private javax.swing.JLabel lblNumGuia;
    private javax.swing.JLabel lblTelefono;
    private javax.swing.JPanel pnlDatosEnvio;
    private javax.swing.JPanel pnlDos;
    private javax.swing.JPanel pnlOpcionesDos;
    private javax.swing.JPanel pnlOpcionesUno;
    private javax.swing.JPanel pnlUno;
    private javax.swing.JScrollPane scrEnvios;
    private javax.swing.JTable tblDetalleEnvio;
    private javax.swing.JTable tblEnvios;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtDistribuidor;
    private javax.swing.JTextField txtFecha;
    private javax.swing.JTextField txtNroGuia;
    private javax.swing.JTextField txtTelefono;
    // End of variables declaration//GEN-END:variables
}
